package com.leoman.dao;

import com.leoman.entity.Video;
import com.leoman.entity.VideoData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * VideoDataDao
 * Created by 涂奕恒 on 2016/11/8 0008 下午 2:17.
 */
public interface VideoDataDao extends JpaRepository<VideoData, Integer>, JpaSpecificationExecutor<VideoData> {

    @Query("select a from VideoData a where a.video.companyUser.id = ?1 and a.recordTime >= ?2 and a.recordTime < ?3")
    List<VideoData> findListByCompanyUserId(Integer companyUserId, Long startTime, Long endTime);

    @Query("select a from VideoData a where a.video.companyUser.id = ?1 and a.recordTime >= ?2 and a.recordTime < ?3 and a.video.id = ?4")
    List<VideoData> findListByCompanyUserIdAndVideoId(Integer companyUserId, Long startTime, Long endTime, Integer videoId);

    @Query("select a from VideoData a where a.video.companyUser.id = ?1 and a.recordDate = ?2")
    List<VideoData> findListByCompanyUserIdAndDate(Integer companyUserId, String recordDate);

    @Query("select a from VideoData a where a.video.companyUser.id = ?1 and a.recordDate = ?2 and a.video.id = ?3")
    List<VideoData> findListByCompanyUserIdAndDateAndVideoId(Integer companyUserId, String recordDate, Integer videoId);

    @Query("select a from VideoData a where a.video.companyUser.id = ?1")
    List<VideoData> findListByCompanyUserId(Integer companyUserId);

    @Query("select a.video from VideoData a where a.video.companyUser.id = ?1 and a.recordTime >= ?2 and a.recordTime < ?3 group by a.video.id")
    List<Video> findListOne(Integer companyUserId, Long startTime, Long endTime);

    @Query("select sum(a.playNum) from VideoData a where a.video.companyUser.id = ?1 and a.recordTime >= ?2 and a.recordTime < ?3 group by a.video.id")
    List<Long> findListTwo(Integer companyUserId, Long startTime, Long endTime);

    @Query("select a from VideoData a where a.video.id = ?1")
    List<VideoData> findListByVideoId(Integer videoId);
}